//1、自定义头文件放在最上面
//2、C的头文件
//3、CPP的头文件
//4、第三方库头文件
#include "myLog.h"

#include <log4cpp/PatternLayout.hh>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/Priority.hh>

using std::cout;
using std::endl;

namespace du {

using namespace log4cpp;

Mylog::Mylog():_mycat(Category::getRoot().getInstance("Mycat")) {
    //准备工作
    PatternLayout *ptn1 = new PatternLayout();
    ptn1->setConversionPattern("%d %c [%p] %m%n");
    PatternLayout *ptn2 = new PatternLayout();
    ptn1->setConversionPattern("%d %c [%p] %m%n");

    OstreamAppender *pOsApp = new OstreamAppender("console", &cout);
    pOsApp->setLayout(ptn1);
    FileAppender *pFileApp = new FileAppender("pFileapp", "du.log");
    pFileApp->setLayout(ptn2);

    //设计mycat
    _mycat.setPriority(Priority::DEBUG);
    _mycat.addAppender(pOsApp);
    _mycat.setAppender(pFileApp);
    /* cout << "Mylog()" << endl; */
}

Mylog::~Mylog() {
    Category::shutdown();
    /* cout << "~Mylog()" << endl; */
}

Mylog *Mylog::_pInstance = nullptr;

}// end of namespace du










